package in.muton.panels.paginator.components.listitems;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.pages.coursepages.CourseDept;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.url.URLHelper;
import in.muton.edushare.wicket.models.CayenneModel;
import in.muton.panels.paginator.badgehelpers.course.CourseBadgeInterface;
import in.muton.panels.paginator.helpers.deletelinks.CourseDelete;
import in.muton.panels.paginator.helpers.links.CourseLink;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.IModel;

import com.edushare.common.vo.CourseInstances;
import com.edushare.common.vo.Courses;

public class CourseListItem extends EdusharePanel {

	
	public CourseListItem(String id, EduShareBasePage page,
			IModel<CourseInstances> instModel, CourseBadgeInterface bif){
		super(id, page);
		this.cInst = instModel;
		this.bif = bif;
		course = new CayenneModel<Courses>(instModel.getObject().getCourse());
		add(new CourseLink("nameLink", instModel, "name"));
		init();
	}
	
	public CourseListItem(String id, EduShareBasePage page, IModel<Courses> model,
			CourseBadgeInterface bif, int dummy){
		super(id, page);
		this.course = model;
		this.bif = bif;
		add(new CourseLink("nameLink", model, "name",0));
		init();
	}
	
	public void init(){
		PageParameters p;
		if(cInst != null)
			p = EntityPageParams.getParams(cInst);
		else
			p = EntityPageParams.getParams(course);
		
		add(new BookmarkablePageLink<Void>("people", URLHelper
				.getCoursePeoplePageClass(), p));
		add(new BookmarkablePageLink<Void>("dept", CourseDept.class, p));
		add(new CourseDelete("delete", this, bif, course));
	}
	
	private static final long serialVersionUID = -9014669872646092049L;
	private IModel<CourseInstances> cInst;
	private IModel<Courses> course;
	private CourseBadgeInterface bif;
}
